#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Orange
#property indicator_color2 Blue
#property indicator_color3 Red

int g_applied_price_76 = PRICE_CLOSE;
int gi_80 = 21;
int gi_84 = 0;
double gd_88 = 0.0;
int gi_96 = 1;
int gi_100 = 0;
double gd_104 = 0.0;
int gi_112 = 0;
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
double g_ibuf_128[];
double g_ibuf_132[];
double g_ibuf_136[];
double gda_140[];
int g_index_144;
int gi_148;
int gi_152;
int gi_156 = 4;
double gd_160;
int ti_unused_0;
double gd_168;
double gd_176;
double gd_184;
double gd_192;
double gd_200;
double gd_208 = 3.1415926535;
bool gi_216 = FALSE;
bool gi_220 = FALSE;

int init() {
   IndicatorBuffers(6);
   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, g_ibuf_116);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 171);
   SetIndexBuffer(1, g_ibuf_120);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, 171);
   SetIndexBuffer(2, g_ibuf_124);
   SetIndexBuffer(3, g_ibuf_128);
   SetIndexBuffer(4, g_ibuf_132);
   SetIndexBuffer(5, g_ibuf_136);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   string ls_0 = "GJ1";
   IndicatorShortName(ls_0);
   SetIndexLabel(0, "GJ1");
   SetIndexLabel(1, "Up");
   SetIndexLabel(2, "Dn");
   SetIndexShift(0, gi_84);
   SetIndexShift(1, gi_84);
   SetIndexShift(2, gi_84);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexEmptyValue(2, EMPTY_VALUE);
   SetIndexDrawBegin(0, gi_80 * gi_156 + gi_80 + 1);
   SetIndexDrawBegin(1, gi_80 * gi_156 + gi_80 + 1);
   SetIndexDrawBegin(2, gi_80 * gi_156 + gi_80 + 1);
   gd_160 = 3.0 * gd_208;
   gi_148 = gi_80 - 1;
   gi_152 = gi_80 * gi_156 + gi_148;
   ArrayResize(gda_140, gi_152);
   gd_192 = 0;
   for (g_index_144 = 0; g_index_144 < gi_152 - 1; g_index_144++) {
      if (g_index_144 <= gi_148 - 1) gd_176 = 1.0 * g_index_144 / (gi_148 - 1);
      else gd_176 = (g_index_144 - gi_148 + 1) * (2.0 * gi_156 - 1.0) / (gi_156 * gi_80 - 1.0) + 1.0;
      gd_168 = MathCos(gd_208 * gd_176);
      gd_200 = 1.0 / (gd_160 * gd_176 + 1.0);
      if (gd_176 <= 0.5) gd_200 = 1;
      gda_140[g_index_144] = gd_200 * gd_168;
      gd_192 += gda_140[g_index_144];
   }
   return (0);
}

int start() {
   int li_12;
   double l_ima_16;
   double ld_24;
   double ld_32;
   double ld_40;
   double ld_48;
   string ls_56;
   int l_ind_counted_8 = IndicatorCounted();
   if (l_ind_counted_8 > 0) li_12 = 0;
   if (l_ind_counted_8 < 0) return (0);
   if (l_ind_counted_8 == 0) li_12 = Bars - gi_152 - 1;
   if (l_ind_counted_8 < 1) {
      for (int l_index_0 = 1; l_index_0 < gi_80 * gi_156 + gi_80; l_index_0++) {
         g_ibuf_116[Bars - l_index_0] = 0;
         g_ibuf_120[Bars - l_index_0] = 0;
         g_ibuf_124[Bars - l_index_0] = 0;
      }
   }
   for (int li_4 = li_12; li_4 >= 0; li_4--) {
      gd_184 = 0;
      for (l_index_0 = 0; l_index_0 <= gi_152 - 1; l_index_0++) {
         l_ima_16 = iMA(NULL, 0, 1, 0, MODE_LWMA, g_applied_price_76, l_index_0 + li_4);
         gd_184 += gda_140[l_index_0] * l_ima_16;
      }
      if (gd_192 > 0.0) g_ibuf_116[li_4] = (gd_104 / 100.0 + 1.0) * gd_184 / gd_192;
      if (gd_88 > 0.0) {
         g_ibuf_132[li_4] = MathAbs(g_ibuf_116[li_4] - (g_ibuf_116[li_4 + 1]));
         ld_24 = 0;
         for (l_index_0 = 0; l_index_0 <= gi_80 - 1; l_index_0++) ld_24 += g_ibuf_132[li_4 + l_index_0];
         g_ibuf_136[li_4] = ld_24 / gi_80;
         ld_32 = 0;
         for (l_index_0 = 0; l_index_0 <= gi_80 - 1; l_index_0++) ld_32 += MathPow(g_ibuf_132[li_4 + l_index_0] - (g_ibuf_136[li_4 + l_index_0]), 2);
         ld_40 = MathSqrt(ld_32 / gi_80);
         ld_48 = gd_88 * ld_40;
         if (MathAbs(g_ibuf_116[li_4] - (g_ibuf_116[li_4 + 1])) < ld_48) g_ibuf_116[li_4] = g_ibuf_116[li_4 + 1];
      }
      if (gi_96 > 0) {
         g_ibuf_128[li_4] = g_ibuf_128[li_4 + 1];
         if (g_ibuf_116[li_4] - (g_ibuf_116[li_4 + 1]) > ld_48) g_ibuf_128[li_4] = 1;
         if (g_ibuf_116[li_4 + 1] - g_ibuf_116[li_4] > ld_48) g_ibuf_128[li_4] = -1;
         if (g_ibuf_128[li_4] > 0.0) {
            g_ibuf_120[li_4] = g_ibuf_116[li_4];
            if (g_ibuf_128[li_4 + gi_100] < 0.0) g_ibuf_120[li_4 + gi_100] = g_ibuf_116[li_4 + gi_100];
            g_ibuf_124[li_4] = EMPTY_VALUE;
            if (gi_112 > 0 && g_ibuf_128[li_4 + 1] < 0.0 && li_4 == 0) {
            }
         }
         if (g_ibuf_128[li_4] < 0.0) {
            g_ibuf_124[li_4] = g_ibuf_116[li_4];
            if (g_ibuf_128[li_4 + gi_100] > 0.0) g_ibuf_124[li_4 + gi_100] = g_ibuf_116[li_4 + gi_100];
            g_ibuf_120[li_4] = EMPTY_VALUE;
            if (gi_112 > 0 && g_ibuf_128[li_4 + 1] > 0.0 && li_4 == 0) {
            }
         }
      }
   }
   if (g_ibuf_128[2] < 0.0 && g_ibuf_128[1] > 0.0 && Volume[0] > 1.0 && !gi_216) {
      ls_56 = " " + Symbol() + " M" + Period() + ": Signal for BUY";
      if (gi_112 > 0) {
      }
      gi_216 = TRUE;
      gi_220 = FALSE;
   }
   if (g_ibuf_128[2] > 0.0 && g_ibuf_128[1] < 0.0 && Volume[0] > 1.0 && !gi_220) {
      ls_56 = " " + Symbol() + " M" + Period() + ": Signal for SELL";
      if (gi_112 > 0) {
      }
      gi_220 = TRUE;
      gi_216 = FALSE;
   }
   return (0);
}

